package leetcode100;

import java.util.LinkedList;

public class MinStack {
    private LinkedList<Integer> mainStack;
    private LinkedList<Integer> minStack;

    public MinStack() {
        this.mainStack = new LinkedList<>();
        this.minStack = new LinkedList<>();
    }

    public void push(int val) {
        if (this.mainStack.isEmpty()) {
            this.minStack.push(val);
            this.mainStack.push(val);
            return ;
        }
        this.mainStack.push(val);
        this.minStack.push(Math.min(this.minStack.peek(),val));

    }

    public void pop() {
        if (this.mainStack.isEmpty()) {
            return;
        }
        this.mainStack.pop();
        this.minStack.pop();
    }

    public int top() {
        return this.mainStack.peek();
    }

    public int getMin() {
        return this.minStack.peek();
    }
}
